package com.example.myapplication4;

import ohos.ace.ability.AceAbility;
import ohos.aafwk.content.Intent;

import java.util.ArrayList;
import java.util.List;

public class MainAbility extends AceAbility {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        //动态权限的申请与获取
        String []permissions={
                "ohos.permission.LOCATION",
                "ohos.permission.LOCATION_IN_BACKGROUND"};
        //可动态授权的权限
        List<String> permissionsToProcess=new ArrayList<>();
        //遍历需要处理的权限
        for(String permission:permissions){
            if(verifySelfPermission(permission)!=0 && canRequestPermission(permission)){
                permissionsToProcess.add(permission);
            }
        }
        //弹窗申请权限
        requestPermissionsFromUser(permissionsToProcess.toArray(new String[0]),0);
    }


    @Override
    public void onStop() {
        super.onStop();
    }
}
